package cn.lzit.sy3;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class ResultServlet
 */
public class ResultServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     * response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String name = request.getParameter("username");// 获取用户姓名
        String pwd = request.getParameter("password");// 获取用户密码
        String age = request.getParameter("password");// 获取用户年龄
        String sex = request.getParameter("sex");// 获取用户性别
        String[] loves = request.getParameterValues("loves");// 获取用户爱好
        String email = request.getParameter("email");// 获取用户EAMIL
        String tel = request.getParameter("tel");// 获取用户联系电话
// 中文乱码处理，取决于你的tomcat版本，如果版本高于6.5是不需要的
        name = new String(name.getBytes("ISO-8859-1"), "UTF-8");
        for (int i = 0; i < loves.length; i++)
            loves[i] = new String(String.valueOf(i).getBytes("ISO-8859-1"), "UTF-8");
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter pWriter = response.getWriter();
        pWriter.print("<body bgcolor='pink'>");
        if (pwd.length() < 6 || pwd.length() > 10)
            System.out.println("Password length is invalid.");
// 显示用户的注册信息
        pWriter.print("用户名: " + name + "<br/>");
        pWriter.print("密码:" + pwd + "<br/>");
        pWriter.print("年龄:" + age + "<br/>");
        pWriter.print("性别:" + sex + "<br/>");
        pWriter.print("爱好: " + Arrays.toString(loves)+ "<br/>");
        pWriter.print("Email:" + email + "<br/>");
        pWriter.print("Tel:" + tel + "<br/>");
        pWriter.print("</body>");
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
// TODO Auto-generated method stub
        doGet(request, response);
    }
}
